package com.snopy.stream;

import lombok.extern.slf4j.Slf4j;

import java.io.*;
import java.net.URL;
import java.nio.file.*;
import java.util.*;

/**
 * @author snopy
 * @version 1.0.0
 * @classname DemoPath
 * @description
 * @email 77912204@qq.com
 * @date 2022/07/30 11:09
 */
@Slf4j

public class DemoPath {
    public static final int _1G = 1024 * 1024 * 1024;
    public static final int _1M = 1024 * 1024;
    public static void main(String[] args) throws IOException {
        URL resource = DemoPath.class.getClassLoader().getResource("config.properties");
        Properties properties = new Properties();
        if (null != resource){
            properties.load(resource.openStream());
        }
        StringBuilder filePath = new StringBuilder();
        filePath.append(properties.get("upload.path")).append(File.separatorChar);
        Calendar instance = Calendar.getInstance();
        filePath.append(instance.get(Calendar.YEAR)).append(instance.get(Calendar.MONTH)).append(File.separatorChar);
        File fl = new File(filePath.toString());
        if(!fl.exists()){
            fl.mkdirs();
        }
        File in = new File("Sonata_java8/src/main/resources/xanadu.txt");
        filePath.append("copy").append(instance.get(Calendar.DATE)).append(".txt");

        log.info("filePath{}",filePath.toString());
        Paths.get(filePath.toString()).toFile().createNewFile();
        File newFile = new File(filePath.toString());
        //PrintWriter out = new PrintWriter(new File());
        if (!in.exists()){
            log.info("file not exist!");
            return;
        }

        Scanner c = new Scanner(System.in);
        PrintWriter out = null;
        try{
            out = new PrintWriter(newFile);
            out.println(c.next());
            properties = System.getProperties();
            for (Map.Entry<Object, Object> entry : properties.entrySet()) {
                out.println(entry.getKey()+" : "+entry.getValue());
            }
        }finally {
            if (out != null){
                out.close();
            }
        }
    }
}
